import 'package:flutter/material.dart';
import 'package:city_corner/providers/main-page/filter-panel/index.dart';
import 'package:provider/provider.dart';

class FilterBar extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _FilterBar();
  }
}

class _FilterBar extends State<StatefulWidget> {
  List<Widget> textBtn() {
    const textList = [
      {"value": 'local', "label": '区域'},
      {"value": 'rent', "label": '租金'},
      {"value": 'sort', "label": '排序'},
      {"value": 'more', "label": '更多'}
    ];
    int len = textList.length;
    List<Widget> btnList = new List<Widget>(len);
    for (int i = 0; i < len; i++) {
      btnList[i] = new InkWell(
        onTap: () {
          var _curOpt = textList[i]['value'];
          var filterModel = Provider.of<FilterModel>(context, listen: false);
          filterModel.curOpt == _curOpt
              ? filterModel.setCurOpt('')
              : filterModel.setCurOpt(_curOpt);
        },
        child: new Row(children: [
          new Text(textList[i]["label"]),
          new IconButton(icon: Icon(Icons.arrow_drop_down))
        ]),
      );
    }
    return btnList;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 50.0,
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: textBtn(),
      ),
    );
  }
}
